//定义原型
interface Prototype {
    clone(): Prototype
}

//实现原型的具体类
class Dog implements Prototype {
    private _name: string
    private _birthYear: number
    private _sex: string
    private _presentYear: number

    public get name(): string {
        return this._name
    }
    public set name(value: string) {
        this._name = value
    }
   
    public get birthYear(): number {
        return this._birthYear
    }
    public set birthYear(value: number) {
        this._birthYear = value
    }
   
    public get sex(): string {
        return this._sex
    }
    public set sex(value: string) {
        this._sex = value
    }
    
    public get presentYear(): number {
        return this._presentYear
    }
    public set presentYear(value: number) {
        this._presentYear = value
    }

    constructor() {
        this._name = "pipi"
        this._birthYear = 2016
        this._sex = "雄"
        this._presentYear = 2022
     }

     public getInfo():string{
        return  `这只狗叫${this.name}，性别${this.sex}，${this.birthYear}年出生，今年${this.presentYear - this.birthYear}岁了`
     }

     //实现复制
    public clone(): Prototype {
        return Object.create(this)
    }
}

const PrototypeTest = ():void =>{
    const dog = new Dog()
    console.log("原型的" + dog.getInfo());

    dog.birthYear = 2011
    const dog2 = dog.clone();
    console.log("修改后的" + dog.getInfo());
}

PrototypeTest()